package com.dragon.tools.pojo;

import java.util.List;

public class SqlElement {

    private String databaseName;
    private String tabName;
    private String tabComment;
    private String tabType;
    private List<String> columnList;
    private List<String> columnTypeList;
    private List<String> columnCommList;
    private String parColumn;
    private String parType;
    private String parComm;
    private String delimited = ",";
    private String storeType = "TEXTFILE";
    private String hdfsPath = "";

    // 生成SQL模板，根据自身属性填充
    public String generate() {
        StringBuffer sql = new StringBuffer();

        sql.append("CREATE "+ tabType +" TABLE `" + this.databaseName + "`.`" + this.tabName + "`(\n");
        for (int i = 0; i < columnList.size(); i++) {
            sql.append("  `" + columnList.get(i) + "` " + columnTypeList.get(i) + " COMMENT '" + columnCommList.get(i) + "',\n");
        }
        String sql1 = sql.substring(0, sql.length() - 2);
        sql = new StringBuffer(sql1);
        sql.append("\n)\nCOMMENT '" + tabComment + "'\n");
        sql.append("PARTITIONED BY (`" + parColumn + "` " + parType + " COMMENT '" + parComm + "')\n");
        sql.append("ROW FORMAT DELIMITED FIELDS TERMINATED BY '"+ delimited +"'\n");
        sql.append("STORED AS " + storeType);
        if (!"".equals(hdfsPath)){
            sql.append("\nLOCATION '" + hdfsPath + "'");
        }
        sql.append("\n;");

        return sql.toString();
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    public String getTabName() {
        return tabName;
    }

    public void setTabName(String tabName) {
        this.tabName = tabName;
    }

    public String getTabComment() {
        return tabComment;
    }

    public void setTabComment(String tabComment) {
        this.tabComment = tabComment;
    }

    public String getTabType() {
        return tabType;
    }

    public void setTabType(String tabType) {
        this.tabType = tabType;
    }

    public List<String> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<String> columnList) {
        this.columnList = columnList;
    }

    public List<String> getColumnTypeList() {
        return columnTypeList;
    }

    public void setColumnTypeList(List<String> columnTypeList) {
        this.columnTypeList = columnTypeList;
    }

    public List<String> getColumnCommList() {
        return columnCommList;
    }

    public void setColumnCommList(List<String> columnCommList) {
        this.columnCommList = columnCommList;
    }

    public String getParColumn() {
        return parColumn;
    }

    public void setParColumn(String parColumn) {
        this.parColumn = parColumn;
    }

    public String getParType() {
        return parType;
    }

    public void setParType(String parType) {
        this.parType = parType;
    }

    public String getParComm() {
        return parComm;
    }

    public void setParComm(String parComm) {
        this.parComm = parComm;
    }

    public String getDelimited() {
        return delimited;
    }

    public void setDelimited(String delimited) {
        this.delimited = delimited;
    }

    public String getStoreType() {
        return storeType;
    }

    public void setStoreType(String storeType) {
        this.storeType = storeType;
    }

    public String getHdfsPath() {
        return hdfsPath;
    }

    public void setHdfsPath(String hdfsPath) {
        this.hdfsPath = hdfsPath;
    }

}
